<template>
  <div>
    <el-dialog :visible.sync="dialogVisible">
       <el-input v-model="id" v-show="false"></el-input>
      <el-input v-model="newusername" placeholder="请填入新名字"></el-input>
      <el-button
        type="danger"
        icon="el-icon-close"
        @click="dialogVisible = false"
        >取 消</el-button
      >
      <el-button type="success" icon="el-icon-check" @click="resuename"
        >确 定</el-button
      >
    </el-dialog>
  </div>
</template>
<script>
import { success } from "log-symbols";

export default {
  name: "reusername",
  data() {
    return {
      newusername: "",
      // oldusername: "",
      dialogVisible: false,
      id:''
    };
  },
  methods: {
    resuename() {
      let data = new FormData();
      data.append("newusername", this.newusername);
      data.append("id", this.id);
      this.$axios.post("/reusername", data).then((successResponse) => {
        if (successResponse.data.code === 200) {
          this.open2();
          this.$emit('getusername')
            // this.$emit('reloads')
          // this.getusername()
          this.$router.go(0);
         
          this.open2();
          this.dialogVisible = false;
        } else {
          this.open4();
          this.dialogVisible = false;
        }
        
        
      });
    },
    getusernamebyid() {
      let data = new FormData();
      data.append('id',this.id)
      this.$axios.post("/getusernamebyid",data).then((resp) => {
        this.newusername = resp.data;
        
        console.log(resp);
      });
    },
    open2() {
      this.$message({
        message: "成功修改用户名",
        type: "success",
      });
    },
    open4() {
      this.$message({
        message: "失败修改用户名",
        type: "error",
      });
    },
    getid() {
      this.$axios.get("/getid").then((resp) => {
        this.id = resp.data
        console.log(this.id);
      })
      
    }
  },
  mounted: function () {
    // this.getusername();
    this.getid();
  },
};
</script>
<style scoped>
</style>